import random
import json
import numpy
#模拟交易节点
nodes = random.sample(range(1, 1000), 600)

#模拟节点类型
groups = [1, 2, 3, 4]

#模拟节点交易情况
node_info = {}
info1 = []
for ele in nodes:
    temp = {}
    temp['id'] = str(ele)
    temp['group'] = random.sample(groups, 1)[0]
    info1.append(temp)

node_info['nodes'] = info1

temp_list = list()
for i in nodes:
    temp = nodes
    temp.remove(i)
    num = abs(int(numpy.random.randn()*5)) + 1
    tar = random.sample(temp, num)
    for j in tar:
        temp = [i, j]
        temp_list.append(temp)

edge_info = []
for ele in temp_list:
    temp = {}
    temp['source'] = ele[0]
    temp['target'] = ele[1]
    temp['value'] = abs(int(numpy.random.randn()*10))
    edge_info.append(temp)
node_info['links'] = edge_info

with open('node_express_qs/public/test.json', 'w') as f:
    f.write(json.dumps(node_info))